#include "xyz.h"
#include <stdlib.h>
#include <assert.h>
#include <math.h>

#define almost_equal(a, b) (fabs(a-b) <= (fabs(a) * 1e-10))

int main(void) {
  int i;
  struct xyz_float a;
  struct xyz_float b;

  printf("Verifying consistency of 1,000,000 manhattan / 1-norm and euclidian / 2-norm distances.\n");

  for(i = 0; i < 1000000; i++) {

    double manhattan;
    double p_norm_1;
    double p_norm_2;
    double euclidian;

    a.x = 1000.0 * rand()/(RAND_MAX+1.0);
    a.y = 1000.0 * rand()/(RAND_MAX+1.0);
    a.z = 1000.0 * rand()/(RAND_MAX+1.0);
    b.x = 1000.0 * rand()/(RAND_MAX+1.0);
    b.y = 1000.0 * rand()/(RAND_MAX+1.0);
    b.z = 1000.0 * rand()/(RAND_MAX+1.0);
    
    manhattan = xyz_float_manhattan_distance(&a,&b);

    p_norm_1  = xyz_float_p_norm_distance(&a, &b, 1.0);
    p_norm_2  = xyz_float_p_norm_distance(&a, &b, 2.0);

    euclidian = xyz_float_distance(&a, &b);

    assert(almost_equal(manhattan, p_norm_1));
    assert(almost_equal(euclidian, p_norm_2));

  }

  printf("Done.  (Success!)\n");

  return 0;

}
